var pg;
var status = 'click'; //事件状态 上线换成 touchend（触摸事件），click为测试状态
var cookie = $.AMUI.utils.cookie; //地址定位
var u = navigator.userAgent;
var isBeiZhu = u.indexOf('BeiZ_Wap/ECCF3EFE2A3E11DAED68A4F63B8E2D14') > -1 || u.indexOf('BeiZ_Wap/ECCF3EFE2A3E11DAED68A4F63B8E2D14') > -1; //是否着想应用内部打开
var isIos = u.indexOf('BeiZ_Wap/ECCF3EFE2A3E11DAED68A4F63B8E2D15') > -1 || u.indexOf('BeiZ_Wap/ECCF3EFE2A3E11DAED68A4F63B8E2D15') > -1; //是否着想应用内部打开
/**
* 获取host域名
 * @returns
 */
function hostUrl() {
    var storeId = 3578748;
    var pathname = location.pathname;
    if (pathname) {
        var urlArray = pathname.split('/');
        var regPos = /^\d+(\.\d+)?$/;
        if (regPos.test(urlArray[1])) {
            storeId = urlArray[1];
        }
    }
    return location.protocol+'//'+location.host+'/'+storeId+'/tourism/';
}

/**
 * 验证是否登录
*/
function checkLogin()
{
    $.ajax({
        type:'post',
        async:false,
        url:hostUrl()+'tourismcart/checkLogin',
        dataType:'json',
        success:function(json){
            if(!(json.status)){
                window.location.href = json.messages;
            }
        }
    })
}

/**
 * 小弹框
 * @param $errorMessage  提示消息
 */
function alertMessage($errorMessage){
    layer.open({
        content: $errorMessage,
        style: 'background-color:rgba(0, 0, 0, 0.6); color:#d7d7d7; border:none;text-align:center;',
        time: 2,
        shade: false
    });
}

/***
 * 收藏页面
 * @param goods_attr_id
 * @param obj
 * @param status--1,商品详情页面  2购物车页面
 */
function  addShrine(goods_attr_id,obj,status)
{
    $.ajax({
        type:'post',
        async:false,
        url:hostUrl()+'tourismcart/ajaxShrine',
        data:{'id':goods_attr_id},
        dataType:'json',
        success:function(json){
            if(json.status){
                if(json.messages == 'yes'){
                    if(status==1){
                    	$(obj).parents('li').find('i').addClass('active');
                    	$('.collect').text('已收藏');
                    }else{
                        $(obj).addClass('active');
                    }
                    alertMessage('关注成功');
                }else{
                    if(status==1){
                    	 $(obj).parents('li').find('i').removeClass('active');
                    	 $('.collect').text('收藏');
                    }else{
                        $(obj).removeClass('active');
                    }
                    alertMessage('取消关注');
                }
            }else{
                alertMessage('关注失败');
                window.location.reload();
            }
        }
    })
}
/**
 * 商品详情加减数量
 * @param kind
 * @param obj
 */
function goodsQtyUpdate(kind, obj,limit) {
    var qtyObj = obj.parent('.coll-num').find('.qty');
    var chose = $('.wares-spec .goods_num');
    var n = qtyObj.attr('data-key');
    var c = qtyObj.val();
    if (kind == "up") {
        c++;
    } else if (kind == "down") {
        if (c > 1) c--;
    }
    if((limit>0) &&(c>limit)){
    	alertMessage('限购'+limit+'件');
    	c = limit;
    }
    if (c > n) {
    	alertMessage('库存不足');
        c = n;
    }
    qtyObj.val(c);
    chose.text(c);
    ajaxFreight();
}
/**
 * 商品详情直接更改数量
 * @param obj
 * @param limit
*/
function goodsQtyChange(obj,limit) {
    var c = obj.val();
    var n = obj.attr('data-key');
    var chose = $('.wares-spec .goods_num');
    c = parseInt(c);
    n = parseInt(n);
    if (isNaN(c) || c==0) {
        c = 1;
    }
    if((limit>0) &&(c>limit)){
    	alertMessage('限购'+limit+'件');
    	c = limit;
    }
    if (c > n) {
        c = n;
        alertMessage('库存不足');
    }
    obj.val(c);
    chose.text(c);
    ajaxFreight();
}
/**
 * 加入购物车
 * @param goods_attr_id
 */
function addCart(goods_attr_id){
    var spec = new Array();
    var num = $('input[name=goodsNum]').val();
    $('.wares-click  input:checked').each(function(i){
        spec[i] = $(this).val();
    })
    $.ajax({
        type:'post',
        async:false,
        url:hostUrl()+'tourismcart/addCart',
        data:{'id':goods_attr_id,number:num,sp:spec},
        dataType:'json',
        beforeSend : function (evt, request, settings) {
        },
        success:function(json){
            if(json.status){
            	$('#my-actions').modal('close');
                alertMessage('恭喜您，商品已移至购物车');
            } else {
                alertMessage(json.messages);
                window.location.reload();
            }
        }
    })
}

function ajaxFreight(){ //运费ajax刷新
	
	var qty = $('.qty').val();
	var transport_id = $('.transport-infor').attr('transport_id');
	var transport_cost = $('.transport-infor').attr('transport_cost');
	var uid = $('.transport-infor').attr('uid');
	var goods_attr_id = $('.transport-infor').attr('goods_attr_id');
	var provice = $('.wares-norm .province').text();
	var weight = $('.transport-infor').attr('weight');
	var price = $('.transport-infor').attr('price');
	$.ajax({
        type:'post',
        dataType:'json',
        url:hostUrl()+'goods/ajaxGetFreightPrice',
        data:{transport_id:transport_id,transport_cost:transport_cost,uid:uid,goods_attr_id:goods_attr_id,provice:provice,qty:qty,weight:weight,price:price},
        async:false,
        success:function(data){
            if( data.status ){
            	var price = (data.cost==0) ? '免费' : (data.cost);
            	$('.wares-norm .transport-cost').text(price);
            }
        }
	})
}


//wap立即购买
function purchaseImmediately(id)
{
    var spec = new Array();
    var num = $('input[name=goodsNum]').val();
    $('.wares-click  input:checked').each(function(i){
        spec[i] = $(this).val();
    })
    if (isBeiZhu) {//移动端使用 请勿删除
    	appPurchaseImmediately(id);
    	return false;
    }
    $.ajax({
        type:'post',
        async:false,
        url:hostUrl()+'order/setGoodsInfoCookie',
        data:{'id':id, num:num,sp:spec},
        dataType:'json',
        beforeSend : function (evt, request, settings) {
        },
        success:function(json){
            if(json.status){
                window.location.href = hostUrl()+'order/confirm';
            } else {
                alertMessage(json.messages);
                window.location.reload();
            }
        }
    })
}
//app--购买--kxx--3/18
function appPurchaseImmediately(id){
	var idArray = id;
	var num = $('input[name=goodsNum]').val();
	var spec = [];
	$(".chose-spec li").each(function(){
		if($(this).hasClass('active')){
			var spec_id = $(this).find('input[type="radio"]').attr('value');
			spec.push(spec_id);
		}
	});
	var goods_num = $('input[name=goodsNum]').attr('data-key');
	if(goods_num == 0 || num > goods_num){
		alertMessage('库存不足');
	}else{
		beizhu.GoToAPPShoppingOrders(idArray, num, spec.toString());
	}
}

function loading(){
    $('#loading').show();
}

function closeLoading(){
    $('#loading').hide();
}

/**
 * 推荐更多
 * @param uid
 * @param pg
 */
function ajaxRecommend(uid,pg){
	
	$.ajax({
        type:'post',
        async:false,
        url:hostUrl()+'goods/ajaxRecommend',
        data:{uid:uid,pg:pg},
        dataType:'json',
        success:function(json){
            if(json.status){
                $('.hot-recommend').html(json.html);
                $('.shuaxin').attr('pg',json.pg);
            }
        }
    })
}
/****
 *修改商品数量
 * @param num
 * @param status 1,商品详情  2，购物车
 */
function modifyGoodsNum(_this,num,status){
    obj = $(_this).parent('div.tb-namber').find('input[name=goodsNum]');
    var id = obj.attr('data-id');
    var url = '';
    if(status == 1){
        url = hostUrl()+'tourismcart/validateGoodsNum';
    }else{
        url = hostUrl()+'tourismcart/updateCart';
    }
    var val = parseInt(obj.val());
    val = val + parseInt(num);
    if(val > 0){
        $.ajax({
            type:'post',
            async:false,
            url:url,
            data:{'num':val,'id':id},
            dataType:'json',
            beforeSend : function (evt, request, settings) {
                loading();
            },
            success:function(json){
                closeLoading();
                if(json.status){
                    if(Number(json.messages) <= 1){
                        obj.prev().addClass('tb-no');
                    }else{
                        obj.prev().removeClass('tb-no');
                    }
                    if(obj.next().hasClass('tb-no')){
                        obj.next().removeClass('tb-no');
                    }
                    obj.val(json.messages);
                    if(status == 2){
                        changeSelected();
                    }
                } else {
                    if(json.goods_num > 0){
                        obj.val(json.goods_num);
                    }
                    if(obj.prev().hasClass('tb-no')){
                        obj.prev().removeClass('tb-no');
                    }
                    obj.next().addClass('tb-no');
                    alertMessage(json.messages);
                }
            }
        })
    }else{
        $('input[name=goodsNum]').val(1);
        if(status == 2){
            changeSelected();
        }
    }
}

//获取url 参数
function GetRequest($keyword) {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for(var i = 0; i < strs.length; i ++) {
            theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]);
        }
        return theRequest[$keyword];
    }else{

        return '';
    }
}

$(function() {
    if(isBeiZhu || isIos){
    	$('body').on('click', 'a', function() {
    		var a_href = $(this).attr('href');
	    	if(a_href.indexOf('home/home/index') > -1){//返回APP首页
	    		beizhu.GoToAppHome();
	    		return false;
	    	}else if(a_href.indexOf('home/ucenter/index') > -1){//返回用户中心
	    		beizhu.GoToAppMyInfo();
	    		return false;
	    	}else if(a_href.indexOf('tourism/tourismcart') > -1 && isBeiZhu){//进入购物车
	    		beizhu.GoToShopCart();
	    		return false;
	    	}else if(a_href.indexOf('tourism/tourismprovider/grid') > -1 && isBeiZhu){//进入店铺
	    		var param = 'providerUid';
				var re = new RegExp("" +param+ "=([^&?]*)", "ig");
				var providerUid = (a_href.match(re)) ? (decodeURI(a_href.match(re)[0].substr(param.length+1))) : '';
				if(providerUid != ''){
					beizhu.GoToShopStore(providerUid);
		    		return false;
				}
	    	}else if(a_href.indexOf('tourism/tourism') > -1 && isBeiZhu){//返回商城首页
	    		beizhu.GoToShopHome();
	    		return false;
	    	}else if(a_href.indexOf('login') > -1 || a_href.indexOf('wap/scenic/wap_index/login') > -1) {//返回APP登录页面
	    		beizhu.GoToAppLogin();
	    		return false;
	    	}
    	})
    }

    $('img.lazy').lazyload({
    	effect :"fadeIn",
        threshold :200
    });
    
    
    /*if($('.shopping-offer').size()>0 ){ //优秀供应商的存在
    	
    	$(".shopping-offer").on('click','li',function(){
    	    layer.open({
    	        type: 0,
    	        shadeClose: true, //点击遮罩关闭
    	        content: "<div class='shopping-modal-msg'><img src='images/modal-msg.png' /><a href='javascript: void(0)' class='close'>×</a><p>敬请期待</p></div>",
    	        style: 'background-color:rgba(0, 0, 0, 0.6); color:#d7d7d7; border:none;text-align:center;'
    	    });
    	    $('.laymshade').css('opacity',0);
    	    $(".shopping-modal-msg").on('click','.close',function(){
    	    	layer.closeAll();
    	    })
    	    return false;
    	});
    }*/
    
    /*******************************************商品分类***************************************/
    $('.classify-isory').on(status,'.category-parent',function(){
        var pranetid = $(this).attr('data-id');
        $(this).siblings().removeClass('active');
        $(this).addClass('active');
        $.ajax({
            type:'post',
            async:false,
            url:hostUrl()+'category/ajaxChildrenCategory',
            data:{'pranetId':pranetid},
            dataType:'json',
            beforeSend : function (evt, request, settings) {
                loading();
            },
            success:function(json){
                closeLoading();
                $('#category-children').html(json.html);
                myScroll3.refresh();
            }
        })
    });

    //搜索
    $('#form-list-search').submit(function(){
        var val = $('input[name=keyword]').val();
        if(val.length < 1){
            return false;
        }
        return true;
    });

    $('#confirm-order').submit(function(){
        $(this).find('button[type=submit]').attr('disabled', 'disabled');
        $(this).find('button[type=submit]').html('提交中');
        return true;
    });

    //首页特价
    if($('.seconds-waper').size()>0){  
        var myScroll4 = new $.AMUI.iScroll('.seconds-waper', { eventPassthrough: true, scrollX: true, scrollY: false, preventDefault: false , click:true});
    }
    //商铺
    if($('.offer-waper').size()>0){  
        var myScroll5 = new $.AMUI.iScroll('.offer-waper', { eventPassthrough: true, scrollX: true, scrollY: false, preventDefault: false , click:true});
    }
    //分类
    if($('.page2-waper').size()>0){
        var myScroll2 = new $.AMUI.iScroll('.page2-waper',{ probeType: 3, mouseWheel: true ,  click:true});
    }
    if($('.sort-waper').size()>0){
        var myScroll3 = new $.AMUI.iScroll('.sort-waper',{ probeType: 3, mouseWheel: true ,  click:true});
    }


    /* 切换页面 */
    $('.page1').on(status,'.Toprev',function(event){
        setTimeout(function(){
            $('.page1').addClass('out-none');
        },400);
        $('.page1').addClass('prev');
        $('.page2').removeClass('out-none').addClass('next');
         $("input[name=keyword]").val('').focus();
        event.stopPropagation();
    });
    $('.page2').on(status,'.Tonext',function(event){
        setTimeout(function(){
            $('.page2').addClass('out-none');
        },400);
        $('.page1').removeClass('out-none').removeClass('prev');
        $('.page2').removeClass('next');
        event.stopPropagation();
    });

    /************************************* 订单支付  ************************************************/
        //选择支付方式
    $('div.mode-payment li.mode-li').on(status,'.check-wrapper',function(){
        if($(this).hasClass('active')){
            //$(this).removeClass('active');
        }else{
            $(this).addClass('active');
            $(this).parents('li.mode-li').siblings().find('.check-wrapper').removeClass('active');
        }
    })

    //提交支付方式
    $('div.mode-sure').on(status, '#submit-order-line-pay', function(e){
        var wrapper = $(this).parent().prev().find('li.mode-li .check-wrapper');
        var id = '';
        var num = 0;
        wrapper.each(function(){
            if($(this).hasClass('active')){
                id = $(this).attr('data-id');
                num++;
            }
        });
        if(num == 0 || id.length == 0){
            alertMessage('请选择支付方式');
        } else if(num > 1){
            alertMessage('页面出错');
        } else {
            $(this).attr('disabled', 'disabled');
            $(this).html('正在提交...');
            $('input[name="pay_bank"]').val(id);
            $('form').submit();
        }
       
    })


    /****************************************城市特色******************************************************/
    var exotic = function(){
        var id = $('#my-scrollspy').attr('data-id');
        var count = 10;
        var start = 1;
        var total = $('#my-scrollspy').attr('data-total');
        $('#my-scrollspy').scrollspy({
            animation: 'fade',
            delay: 500
        })
        //城市 页面 下拉刷新
        $('#my-scrollspy').on('inview.scrollspy.amui', function() {
            setTimeout(function(){
                if(start <= total){
                    ajaxExotic(id, count, start);
                    start = parseInt(start+1);
                }else{
                    $('drop-down-load').hide();
                    $('last-page').show();
                }
            }, 1000);

        }).on('outview.scrollspy.amui', function() {
            //console.log('离开视口');
        });

        function ajaxExotic(id, count, start)
        {
            $.ajax({
                type:'post',
                async: false,
                url: hostUrl() + 'exotic/ajaxExotic',
                data:{id:id,count:count,start:start},
                dataType:'json',
                beforeSend:function(){
                    loading();
                },
                success:function(json){
                    closeLoading();
                    $('#city-bd').append(json.html);
                }
            });
        }
    }

    if($('#my-scrollspy').size()> 0){
        exotic();
    }

    /**********          余额支付     ** *****/

    if($('#form-balance-pay').size() > 0){
        $('#form-balance-pay').submit(function(){
            $(this).find('button[type=submit]').attr('disabled', 'disabled');
            $(this).find('button[type=submit]').html('提交中');
            return true;
        });

        $('#form-balance-pay').find('button[type=submit]').removeAttr('disabled');
    }
    
    if($('.offer-collection .collection').size() > 0){ //点击收藏店铺
		$('.collection').on('click','.collect-shop',function(event){
		       var _this = $(this);
		       $.ajax({
		               type  : 'post',
		               async : false,
		               url   : hostUrl()+'tourismprovider/ajaxCollectShop',
		               dataType: 'json',
		               data : {provider_uid:_this.attr('provider_uid')},
		               success:function(data){
		                     if(data.status){
		                    	 _this.css('background-color','#ccc').text(data.content).removeClass('collect-shop');
		                     } else {
		                        console.log(data.content);
		                     }
		               }
		       });
		       event.preventDefault();
		});
	}
 
    if($('.scy-provider-waper .provider-list').size() > 0){ //商铺列表页
    	
    	pg = 2;
    	$('.provider-more-show').scrollspy({
	        animation: 'fade',
	        delay: 500
	    });
    	$('.provider-more-show').on('inview.scrollspy.amui', function(event) {
    		var providerUid = $('.scy-provider-waper').attr('provider-uid');
        	var sort = $('.scy-provider-waper').attr('sort');
        	var category_id = $('.scy-provider-waper').attr('category_id');
        	var keyword = $('.provider-more-show').attr('keyword');
    		$.ajax({
		    	'type':'get',
		    	'dataType':'json',
		    	'async':false,
		    	'url':hostUrl()+'tourismprovider/ajaxMoreProduct',
		    	'data':{'pg':pg,'providerUid':providerUid,'sort':sort,'category_id':category_id,'keyword':keyword},
		    	'success':function(data){
		    		if(data.status){
		    			pg++;
		    			$('.provider-list').append(data.content);
		    			$('img.lazy').lazyload({effect :"fadeIn", threshold :200 });
		    		}else{
		    			$('.provider-more-show').text('已无更多');
		    		}
		    	}
		    })
		    event.preventDefault();
		})
    }
    
    if($('.seek-provider .seek-list').size() > 0){ // 点击分类-类别-加载
        
    	$('.provider-price,.provider-sale').on('click','li',function(event){
    		
    		var sort = $(this).attr('sort');
    		var providerUid = $('.scy-provider-waper').attr('provider-uid');
        	var category_id = $('.scy-provider-waper').attr('category_id');
        	var keyword = $('.scy-provider-waper').attr('keyword');
    		$('.scy-provider-waper').attr('sort',sort);
    		$(this).parents('.outer').addClass('active').siblings().removeClass('active');
    		$(this).addClass('active').siblings().removeClass('active');
    		$('.outer').dropdown('close');
    		$.ajax({
		    	'type':'get',
		    	'dataType':'json',
		    	'async':false,
		    	'url':hostUrl()+'tourismprovider/ajaxMoreProduct',
		    	'beforeSend':function(){loading();},
		    	'data':{'pg':1,'providerUid':providerUid,'sort':sort,'category_id':category_id,'keyword':keyword},
		    	'success':function(data){
		    		if(data.status){
		    			$('.provider-list').html(data.content);
		    			$('img.lazy').lazyload({effect :"fadeIn",threshold :200 });
		    			if(data.num<12){
		    				$('.provider-more-show').hide();
		    			}else{
		    				$('.provider-more-show').show().html('<i class="iconfont am-animation-spin">&#xe604;</i>');
		    				pg = 2;
		    			}
		    			closeLoading();
		    		}else{
		    			closeLoading();
		    		}
		    	}
		    })
		    event.preventDefault();
    	})
    	
    	$('.provider-category').on('click','li',function(event){
    		
    		var category_id = $(this).attr('category_id');
    		var providerUid = $('.scy-provider-waper').attr('provider-uid');
        	var sort = $('.scy-provider-waper').attr('sort');
        	var keyword = $('.scy-provider-waper').attr('keyword');
    		$('.scy-provider-waper').attr('category_id',category_id);
    		$(this).parents('.outer').addClass('active').siblings().removeClass('active');
    		$(this).addClass('active').siblings().removeClass('active');
    		$('.outer').dropdown('close');
    		$.ajax({
		    	'type':'get',
		    	'dataType':'json',
		    	'async':false,
		    	'url':hostUrl()+'tourismprovider/ajaxMoreProduct',
		    	'beforeSend':function(){loading();},
		    	'data':{'pg':1,'providerUid':providerUid,'sort':sort,'category_id':category_id,'keyword':keyword},
		    	'success':function(data){
		    		if(data.status){
		    			$('.provider-list').html(data.content);
		    			$('img.lazy').lazyload({effect :"fadeIn",threshold :200 });
		    			if(data.num<12){
		    				$('.provider-more-show').hide();
		    			}else{
		    				$('.provider-more-show').show().html('<i class="iconfont am-animation-spin">&#xe604;</i>');
		    				pg = 2;
		    			}
		    			closeLoading();
		    		}else{
		    			closeLoading();
		    		}
		    	}
		    })
    		event.preventDefault();
    	})
    }
    
    if( $('.offer-ad').size() > 0 ){ //隐藏
    	$('.offer-ad').on('click','.ad-close',function(){
			$('.offer-ad').fadeOut();
		});
    }
    
    if( $('.wares-tags').size()>0 ){//商品详情
   	    $('.wares-tags ul').find('a').on('opened.tabs.amui',function(event) {
 			var top = $('.wares-tags').offset().top;
 		    $('html, body').animate({
 		    	scrollTop:top
 		    }, '500');
 		    event.stopPropagation();
 		});
    }
    
    if( $('.wares-spec').size()>0 ){//商品详情
	   	$('.wares-spec').on('click','.wares-click li',function(event){
	   		
	   		$(this).parent().children('.spec').prop('checked', false);
		    $(this).addClass('active').siblings().removeClass('active');
		    $(this).children('.spec').prop('checked', true);
		    event.stopPropagation();
	   	}); 
    }
    
    if( $('.wares-room').size()>0 ){ //商品详情热门推荐
    	var uid = $('.shuaxin').attr('uid');
    	var pg = parseInt($('.shuaxin').attr('pg'))+1;
    	ajaxRecommend(uid,pg);
    	
    }
    if( $('.tourism-infor').size()>0 ){ // 运费的ajax 刷新
    	
    	ajaxFreight();
    	$('.city-head').on('click','.city-return',function(event){
    		$('#doc-city').offCanvas('close');
    		event.stopPropagation();
    	});
    	$('.wares-city').on('click','.city-name li',function(event){ 
    		var address = $(this).find('p').text();
    		$(this).addClass('active').siblings().removeClass('active');
    		$('#doc-city').offCanvas('close');
    		$('.wares-norm .province').text(address);
    		cookie.set('province',address,43520);
    		ajaxFreight();
    		event.stopPropagation();
    	});
    	$('.wares-head').on('click','.share',function(){  //分享
			$('.add-share').toggle();
		});
    	
    	$('.wares-room').on('click','.shuaxin',function(event){ // 换一批
			var _this = $(this);
			var uid = _this.attr('uid');
	    	var pg  = parseInt(_this.attr('pg'))+1;
			_this.addClass('active');
			var stop = setTimeout(function() {
				_this.removeClass('active');
	        }, 500);
			ajaxRecommend(uid,pg);
			event.stopPropagation();
		});
    	
    }
    
    
    if( $('.talk-text .product-reviews').size() > 0){//商品详情评价
    	 $('#reviews-more').scrollspy({
             animation: 'fade',
             delay: 500
         });
    	 $('#reviews-more').on('inview.scrollspy.amui', function() { //商品详情评价分页
    		 var pg = parseInt($('#reviews-more').attr('pg')) + 1;
    		 $.ajax({
                 type : 'get',
                 dataType : 'json',
                 async : true,
                 data : {pg:pg},
                 url : hostUrl() + 'goods/ajaxReview'+location.search,
                 success : function (data){
                         if (data.status) {
                        	 $('#reviews-more').attr('pg',data.pg);
                        	 $('.product-reviews').append(data.html);
                         } else {
                             $('.sec-load').addClass('am-hide');
                             $('.no-more').removeClass('am-hide');
                         }
                     }
             });
    	 });
    	 $('.reviews-score').on('click','a',function(e){
             $(this).addClass('active').siblings().removeClass('active');
             var url = $(this).attr('href');
             $.ajax({
         	     type : 'post',
         	     url  :  url,
         	     async:  false,
         	     beforeSend:function(){
          	    	 $('.no-more').addClass('am-hide');
             	 },
         	     dataType: 'json',
         	     success:function(data){
	           	     if(data.status){
	                       $('.product-reviews').html(data.html);
	                       if(data.num >= 15){
	                    	   $('#reviews-more').removeClass('am-hide').attr('pg',data.pg);
	                       }
	               	 }else{
	                       $('.product-reviews').html('<p>暂无评价</p>');
	               	 }
             	 }
             })
             e.preventDefault();
             return false;
        })
    }
    
    $('body').on('click','.share-link, .sales-share',function(e) {//店铺分享
    	$('.recom-alert').modal();
        var link = $(this).attr('data-link');
        var name = $(this).attr('data-name');
        var img = $(this).attr('data-img');
        $('.am-modal-actions li a').attr('href', link).attr('data-name', name).attr('data-img', img);
        e.preventDefault();
    });
    
    $('.wares-title').on('click','.tourism-share',function(e) {//详情分享
    	$('.recom-alert').modal();
        var link = $(this).attr('data-link');
        var name = $(this).attr('data-name');
        var img = $(this).attr('data-img');
        $('.am-modal-actions li a').attr('href', link).attr('data-name', name).attr('data-img', img);
        e.preventDefault();
    });
    
    $('.am-modal-actions').on('click','.qq',function(event){
        var _width = 320;
        var _height = 640;
        var _top  = 10;
        var _left = 10;
        var _shareUrl  = 'http://connect.qq.com/widget/shareqq/index.html?';
        _shareUrl += 'url=' + encodeURIComponent($(this).attr('href'));
        _shareUrl += '&title=' + encodeURIComponent($(this).attr('data-name'));
        _shareUrl += '&desc=' + encodeURIComponent('分享的描述');
        window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',top='+_top+',left='+_left+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
        event.preventDefault();
    });
    
    $('.am-modal-actions').on('click','.weibo',function(event){
        var _shareUrl = '';
        var _width = 320;
        var _height = 640;
        _shareUrl += 'http://v.t.sina.com.cn/share/share.php?&appkey=895033136';     //真实的appkey ，必选参数
        _shareUrl += '&url='+ encodeURIComponent($(this).attr('href'));     //参数url设置分享的内容链接|默认当前页location，可选参数
        _shareUrl += '&title=' + encodeURIComponent($(this).attr('data-name'));    //参数title设置分享的标题|默认当前页标题，可选参数
        _shareUrl += '&source=' + encodeURIComponent('');
        _shareUrl += '&sourceUrl=' + encodeURIComponent('');
        _shareUrl += '&content=' + 'utf-8';   //参数content设置页面编码gb2312|utf-8，可选参数
        _shareUrl += '&pic=' + encodeURIComponent($(this).attr('data-img'));  //参数pic设置图片链接|默认为空，可选参数
        window.open(_shareUrl,'_blank','toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0,' + 'width=' + _width + ',height=' + _height + ',top=' + (screen.height-_height)/2 + ',left=' + (screen.width-_width)/2);
        event.preventDefault();
    });

    $('.am-modal-actions').on('click','.tecent-weibo',function(event){
        event.preventDefault();
        var _width = 320;
        var _height = 640;
        var _top  = 10;
        var _left = 10;
        var _shareUrl = 'http://v.t.qq.com/share/share.php?';
        _shareUrl += 'title=' + encodeURIComponent($(this).attr('data-name'));    //分享的标题
        _shareUrl += '&url=' + encodeURIComponent($(this).attr('href'));    //分享的链接
        _shareUrl += '&appkey=5bd32d6f1dff4725ba40338b233ff155';    //在腾迅微博平台创建应用获取微博AppKey
        _shareUrl += '&site=' + encodeURIComponent('');   //分享来源
        _shareUrl += '&pic=' + encodeURIComponent($(this).attr('data-img'));    //分享的图片，如果是多张图片，则定义var _pic='图片url1|图片url2|图片url3....'
        window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',left='+_left+',top='+_top+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
        event.preventDefault();
    });
    
    $('.am-modal-actions').on('click','.qq-zone',function(event){
       event.preventDefault();
       var _width = 320;
       var _height = 640;
       var _top = 10;
       var _left = 10;
       var _shareUrl  = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?';
       _shareUrl += 'url=' + encodeURIComponent($(this).attr('href'));   //参数url设置分享的内容链接|默认当前页location
       _shareUrl += '&showcount=' + 0;      //参数showcount是否显示分享总数,显示：'1'，不显示：'0'，默认不显示
       _shareUrl += '&desc=' + encodeURIComponent('分享的描述');    //参数desc设置分享的描述，可选参数
       _shareUrl += '&summary=' + encodeURIComponent('分享摘要');    //参数summary设置分享摘要，可选参数
       _shareUrl += '&title=' + encodeURIComponent($(this).attr('data-name'));    //参数title设置分享标题，可选参数
       _shareUrl += '&site=' + encodeURIComponent('');   //参数site设置分享来源，可选参数
       _shareUrl += '&pics=' + encodeURIComponent($(this).attr('data-img'));   //参数pics设置分享图片的路径，多张图片以＂|＂隔开，可选参数
       window.open(_shareUrl,'_blank','width='+_width+',height='+_height+',top='+_top+',left='+_left+',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
       event.preventDefault();
    });
});
